PROG		= atheme-services${PROG_SUFFIX}
HELP_LINGUAS	= es ru

BASE_SRCS =				\
	account.c		\
	atheme.c		\
	arc4random.c		\
	auth.c		\
	authcookie.c		\
	balloc.c		\
	base64.c		\
	channels.c		\
	cidr.c		\
	cmode.c		\
	commandtree.c		\
	ctcp-common.c		\
	conf.c		\
	confparse.c		\
	confprocess.c		\
	connection.c		\
	crypto.c		\
	culture.c		\
	database_backend.c	\
	datastream.c		\
	dlink.c		\
	event.c		\
	flags.c		\
	function.c		\
	help.c		\
	hook.c		\
	linker.c		\
	logger.c		\
	match.c		\
	md5.c			\
	memory.c		\
	module.c		\
	node.c		\
	object.c		\
	packet.c		\
	parse.c		\
	phandler.c		\
	pmodule.c		\
	poll.c		\
	privs.c		\
	ptasks.c		\
	send.c		\
	servers.c		\
	services.c		\
	servtree.c		\
	signal.c		\
	string.c		\
	strshare.c		\
	svsignore.c		\
	symbolmatrix.c	\
	table.c		\
	template.c		\
	tokenize.c		\
	ubase64.c		\
	users.c		\
	uid.c			\
	uplink.c		\
	xmlrpc.c

SRCS = ${BASE_SRCS} version.c

include ../extra.mk
include ../buildsys.mk

CPPFLAGS	+= $(MOWGLI_CFLAGS) $(PCRE_CFLAGS) -I../include -DBINDIR=\"$(bindir)\" -Wall -Wextra -O0 -g
LIBS		+= $(MOWGLI_LIBS) $(PCRE_LIBS) $(RPATH) $(PROG_IMPLIB_LDFLAGS)

build: all

../dist/atheme.conf.userserv-example: ../dist/atheme.conf.example
	(echo '/* atheme.conf.userserv-example, autogenerated from atheme.conf.example */'; \
	sed -e 's@loadmodule "modules/nickserv/identify";@#&@' \
	  -e 's@loadmodule "modules/nickserv/ghost";@#&@' \
	  -e 's@#loadmodule "modules/nickserv/login";@loadmodule "modules/nickserv/login";@' \
	  -e 's/spam;/#spam;/' \
	  -e 's/#no_nick_ownership;/no_nick_ownership;/' \
	  -e 's/nick = "NickServ";/nick = "UserServ";/' \
	  -e 's/user = "NickServ";/user = "UserServ";/' \
	  -e 's/real = "Nickname Services";/real = "User Registration Services";/' ../dist/atheme.conf.example) >../dist/atheme.conf.userserv-example

../dist/atheme.conf.operserv-example: ../dist/atheme.conf.example
	(echo '/* atheme.conf.operserv-example, autogenerated from atheme.conf.example */'; \
	echo '/* This is for an oper services only atheme instance. */'; \
	sed -e '/^\/\* Database backend module/,/^$$/d' \
	  -e '/^\/\* NickServ module/,/^$$/d' \
	  -e '/^\/\* ChanServ module/,/^$$/d' \
	  -e '/modules\/operserv\/akill/d' \
	  -e '/modules\/operserv\/ignore/d' \
	  -e '/modules\/operserv\/soper/d' \
	  -e '/modules\/operserv\/update/d' \
	  -e '/^\/\* MemoServ module/,/^$$/d' \
	  -e '/^\/\* SASL agent module/,/^$$/d' \
	  -e '/^\/\* GameServ module/,/^$$/d' \
	  -e '/modules\/xmlrpc\/account/d' \
	  -e '/modules\/xmlrpc\/channel/d' \
	  -e '/modules\/xmlrpc\/memo/d' \
	  -e 's/name = "services.int"/name = "operserv.int"/' \
	  -e 's/desc = ".*"/desc = "Atheme Operator Services"/' \
	  -e 's/numeric = "00A"/numeric = "00B"/' \
	  -e '/\/\*.*enforce_expire/,/enforce_delay =/d' \
	  -e 's/expire = .*;/expire = 1;/' \
	  -e 's/nick = "OperServ";/nick = "OperServ2";/' \
	  -e 's/nick = "Global";/nick = "Global2";/' \
	  -e 's/spam;/#spam;/' \
	  -e 's/port = 8080/port = 8081/' ../dist/atheme.conf.example) >../dist/atheme.conf.operserv-example

install-extra: ../dist/atheme.conf.userserv-example ../dist/atheme.conf.operserv-example
	-$(INSTALL) -m 755 -d $(DESTDIR)$(prefix)
	-$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
	-$(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir)
	-$(INSTALL) -m 755 -d $(DESTDIR)$(localstatedir)
	-$(INSTALL) -m 755 -d $(DESTDIR)$(DOCDIR)
	-$(INSTALL) -m 755 -d $(DESTDIR)$(LOGDIR)
	-$(INSTALL) -m 755 -d $(DESTDIR)$(RUNDIR)
	-$(INSTALL) -m 755 -d $(DESTDIR)$(DATADIR)
	-$(INSTALL) -m 755 -d $(DESTDIR)$(SHAREDIR)/help
	$(INSTALL) -m 600 -c ../dist/atheme.conf.example $(DESTDIR)$(sysconfdir)
	$(INSTALL) -m 644 -c ../dist/atheme.motd.example $(DESTDIR)$(sysconfdir)
	[ -r $(DESTDIR)$(sysconfdir)/atheme.motd ] || $(INSTALL) -m 644 -c ../dist/atheme.motd.example $(DESTDIR)$(sysconfdir)/atheme.motd || :
	$(INSTALL) -m 600 -c ../dist/atheme.conf.userserv-example $(DESTDIR)$(sysconfdir)
	$(INSTALL) -m 600 -c ../dist/atheme.conf.operserv-example $(DESTDIR)$(sysconfdir)
	$(INSTALL) -m 644 -c ../dist/atheme.cron.example $(DESTDIR)$(sysconfdir)
	[ -f ${DESTDIR}${bindir}/atheme ] && ${RM} ${DESTDIR}${bindir}/atheme || :
	-${RM} -f $(DESTDIR)${DOCDIR}/HOOKS $(DESTDIR)${DOCDIR}/MODES $(DESTDIR)${DOCDIR}/XMLRPCLIB $(DESTDIR)${DOCDIR}/technical/HOOKS
	(cd ../doc; for i in *; do \
		[ -f $$i ] && $(INSTALL) -m 644 $$i $(DESTDIR)$(DOCDIR); \
		if [ -d $$i ]; then \
			cd $$i; \
			$(INSTALL) -m 755 -d $(DESTDIR)$(DOCDIR)/$$i; \
			for j in *; do \
				[ -f $$j ] && $(INSTALL) -m 644 $$j $(DESTDIR)$(DOCDIR)/$$i; \
			done; \
			cd ..; \
		fi; \
	done; install -m 644 ../NEWS $(DESTDIR)$(DOCDIR)/RELEASE)
	(cd ../help/default; for i in *; do \
		[ -f $$i ] && $(INSTALL) -m 644 $$i $(DESTDIR)$(SHAREDIR)/help; \
		if [ -d $$i ]; then \
			cd $$i; \
			$(INSTALL) -m 755 -d $(DESTDIR)$(SHAREDIR)/help/$$i; \
			for j in *; do \
				[ -f $$j ] && $(INSTALL) -m 644 $$j $(DESTDIR)$(SHAREDIR)/help/$$i; \
			done; \
			cd ..; \
		fi; \
	done)
	-${RM} -f $(DESTDIR)$(SHAREDIR)/help/hostserv/vhostall
	if [ $(USE_NLS) = yes ]; then \
		for lingua in $(HELP_LINGUAS); do \
			$(INSTALL) -m 755 -d $(DESTDIR)$(SHAREDIR)/help/$$lingua; \
			(cd ../help/$$lingua; for i in *; do \
				[ -f $$i ] && $(INSTALL) -m 644 $$i $(DESTDIR)$(SHAREDIR)/help/$$lingua; \
				if [ -d $$i ]; then \
					cd $$i; \
					$(INSTALL) -m 755 -d $(DESTDIR)$(SHAREDIR)/help/$$lingua/$$i; \
					for j in *; do \
						[ -f $$j ] && $(INSTALL) -m 644 $$j $(DESTDIR)$(SHAREDIR)/help/$$lingua/$$i; \
					done; \
					cd ..; \
				fi; \
			done); \
		done; \
	fi

../include/hooktypes.h: mkhooktypes.sh hooktypes.in
	PATH=`getconf PATH` sh mkhooktypes.sh hooktypes.in >../include/hooktypes.h

include .deps
